package cn.hy.prac.service.orderpay;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class OrderPayService {

	
	@Autowired
	private AlipayService alipayService;
	
	/**
	 * 返回支付url
	 * @author haoyi 
	 * @param ordernum
	 * @param payType
	 * @return
	 */
	public String sendPay(String ordernum, int payType, boolean isMobile){
		
		//测试阶段金额为0.01元
		int payMoney = 1 ;
		
		//打包参数，封装URL
		return packPay(ordernum, payMoney, payType, "不管买什么东西都行", isMobile);
	}
	
	
	/**
	 * 封装支付信息
	 * @author haoyi 
	 * @param paynum
	 * @param payMoney
	 * @param payType
	 * @param orderTitle
	 * @return
	 */
	private String packPay(String paynum, int payMoney, int payType, String orderTitle, boolean isMobile){
		
		//此时paytype为2  即支付宝支付，自定义~~~
		String result = null;
		
		try {
			result =  alipayService.getPayUrl(paynum, payMoney, orderTitle, isMobile);
		} catch (Exception e) {
			e.printStackTrace();
			System.out.println("创建支付宝支付链接失败~~~~~~~~~~~~~~~~~~");
		}
		return result;
	}
}
